package com.ruoyi.system.outto.game.impl;

import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.common.utils.HttpUtil;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.system.model.domain.AccountInfo;
import com.ruoyi.system.model.domain.InfoImg;
import com.ruoyi.system.model.domain.SalePartner;
import com.ruoyi.system.model.mapper.AccountInfoMapper;
import com.ruoyi.system.model.mapper.InfoImgMapper;
import com.ruoyi.system.outto.core.LCConstant;
import com.ruoyi.system.outto.game.CommonApi;
import com.ruoyi.system.outto.game.MHWAPI;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;

@Slf4j
@Service
public class MHWAPIImpl implements MHWAPI {

    @Resource
    private InfoImgMapper infoImgMapper;
    @Resource
    private AccountInfoMapper accountInfoMapper;
    @Value("${desc.title}")
    private String descTitle;
    @Resource
    private CommonApi commonApi;


    @Override
    public AjaxResult addGame(AccountInfo accountInfo, Long userId, SalePartner salePartner) {
        pdObject(accountInfo, salePartner);
        Map<String, Object> params = new HashMap<>();
        if ("王者荣耀".equals(accountInfo.getType())) {
            params.put("game_id", 443);
            switch (accountInfo.getRegional()) {
                case "安卓Q":
                    params.put("zone_id", 7717);
                    params.put("server_id", 7718);
                    params.put("phone_type", 1);
                    break;
                case "安卓WX":
                    params.put("zone_id", 9419);
                    params.put("server_id", 9420);
                    params.put("phone_type", 1);
                    break;
                case "苹果Q":
                    params.put("zone_id", 7720);
                    params.put("server_id", 7721);
                    params.put("phone_type", 2);
                    break;
                case "苹果WX":
                    params.put("zone_id", 9566);
                    params.put("server_id", 9567);
                    params.put("phone_type", 2);
                    break;
            }
        } else if ("和平精英".equals(accountInfo.getType())) {
            params.put("game_id", 683);
            switch (accountInfo.getRegional()) {
                case "安卓Q":
                    params.put("zone_id", 8167);
                    params.put("server_id", 8168);
                    params.put("phone_type", 1);
                    break;
                case "安卓WX":
                    params.put("zone_id", 9421);
                    params.put("server_id", 9422);
                    params.put("phone_type", 1);
                    break;
                case "苹果Q":
                    params.put("zone_id", 8167);
                    params.put("server_id", 8168);
                    params.put("phone_type", 2);
                    break;
                case "苹果WX":
                    params.put("zone_id", 9421);
                    params.put("server_id", 9422);
                    params.put("phone_type", 2);
                    break;
            }
        } else if ("英雄联盟".equals(accountInfo.getType())) {
            params.put("game_id", 17);
            String quanfu = "峡谷之巅=7745--7682, 男爵领域=7683--7682,无畏先锋=57--53, 巨龙之巢=60--53, 弗雷尔卓德=56--53, 恕瑞玛=58--53, " +
                    "德玛西亚=55--53, 教育网专区=7256--53, 扭曲丛林=59--53, 比尔吉沃特=54--53,班德尔城=36--33, 战争学院=50--33, 皮尔特沃夫=46--33, " +
                    "均衡教派=41--33, 雷瑟守备=43--33, 钢铁烈阳=38--33, 艾欧尼亚=34--33, 皮城警备=45--33, 卡拉曼达=42--33, 暗影岛=35--33, " +
                    "征服之海=51--33, 黑色玫瑰=39--33, 裁决之地=37--33, 巨神峰=40--33, 水晶之痕=48--33, 守望之海=47--33, 诺克萨斯=44--33, " +
                    "影流=49--33, 祖安=52--33";
            if (StringUtils.equals("网通", accountInfo.getRegional()) || StringUtils.equals("电信",
                    accountInfo.getRegional())) {
                List<String> list1 = Arrays.asList(quanfu.split(","));
                String dd = accountInfo.getDes();
                if (Objects.nonNull(dd)) {
                    if (dd.length() > 50) {
                        dd = dd.substring(0, 50);
                    }
                } else {
                    throw new GlobalException("英雄联盟网通电信比对异常");
                }
                boolean f = false;
                for (String s : list1) {
                    String[] rearray = s.split("=");
                    if (dd.contains(rearray[0].trim())) {
                        f = true;
                        String str2 = rearray[1].trim();
                        String[] str2array = str2.split("--");
                        params.put("zone_id", str2array[1].trim());
                        params.put("server_id", str2array[0].trim());
                        params.put("phone_type", 1);
                        break;
                    }
                }
                if (!f) {
                    throw new GlobalException("英雄联盟网通电信比对未找到大区");
                }
            } else {
                Map qdqMap = stringTOmap(quanfu);
                if (Objects.nonNull(qdqMap.get(accountInfo.getRegional()))) {
                    String qu = qdqMap.get(accountInfo.getRegional()).toString();
                    params.put("zone_id", qu.split("--")[1]);
                    params.put("server_id", qu.split("--")[0]);
                    params.put("phone_type", 1);
                } else {
                    throw new GlobalException("英雄联盟大区未找到");
                }
            }
        } else if ("CF端游".equals(accountInfo.getType())) {
            params.put("game_id", 11);
            String quandaqu = "北京四区=447--442, 辽宁一区=453--442, 吉林一区=452--442, 辽宁二区=454--442, 山东二区=457--442, " +
                    "辽宁三区=455--442, 北京三区=446--442, 山东一区=456--442, 河南一区=449--442, 黑龙江区=451--442, 河北一区=448--442, " +
                    "北京二区=445--442, 北京一区=444--442, 山西一区=458--442, 北方大区=443--442, 河南二区=450--442,浙江二区=440--417, " +
                    "安徽一区=418--417, 上海二区=435--417, 湖南二区=428--417, 江苏二区=430--417, 湖北二区=426--417, 广东二区=421--417, " +
                    "湖南一区=427--417, 湖北一区=425--417, 广东一区=420--417, 广西一区=424--417, 广东四区=423--417, 云南一区=438--417, " +
                    "预备大区=8486--417, 南方大区=432--417, 重庆一区=441--417, 陕西一区=433--417, 江西一区=431--417, 广东三区=422--417, " +
                    "江苏一区=429--417, 浙江一区=439--417, 四川二区=437--417, 福建一区=419--417, 四川一区=436--417, 上海一区=434--417," +
                    "全区全服=463--462,移动专区=461--459, 教育网专区=460--459";
            List<String> list1 = Arrays.asList(quandaqu.split(","));
            String dd = accountInfo.getDes();
            if (Objects.nonNull(dd) && dd.length() > 25) {
                dd = dd.substring(0, 25).replace("1", "一")
                        .replace("2", "二")
                        .replace("3", "三")
                        .replace("4", "四");
            } else {
                throw new GlobalException("穿越火线大区比对处理异常");
            }
            for (String s : list1) {
                String[] rearray = s.split("=");
                if (dd.contains(rearray[0].trim())) {
                    String str2 = rearray[1].trim();
                    String[] str2array = str2.split("--");
                    params.put("zone_id", str2array[1].trim());
                    params.put("server_id", str2array[0].trim());
                    params.put("phone_type", 1);
                    break;
                }
            }
        } else if ("原神".equals(accountInfo.getType())) {
            params.put("game_id", 1028);
            params.put("zone_id", 9465);
            params.put("server_id", 9466);
            params.put("phone_type", 1);
        } else {
            throw new GlobalException("暂未对接买号玩接口此游戏：" + accountInfo.getType());
        }
        params = addOrEditParams(accountInfo, params, 1, salePartner);  // 1 表示是新增
        params = params(accountInfo, params, salePartner);
        String zhfb = "/Channel/Account/addAccount"; // 账号发布接口
        String response = HttpUtils.sendPost(salePartner.getTwoOther() + zhfb,
                StringEscapeUtils.unescapeJava(JSONObject.toJSONString(params).replaceAll("\\s*", "")).replaceAll("\n" +
                        "|\t", ""), "UTF-8");
        JSONObject resultJson = JSONObject.parseObject(response);
        Map<String, Object> result = new HashMap<>();
        if (!"200".equals(resultJson.getString("code"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
            JSONObject res = resultJson.getJSONObject("result");
            String reaccount_id = res.getString("account_id");
            AccountInfo info = accountInfoMapper.selectAccountInfoById(accountInfo.getId());
            info.setMhwid(reaccount_id);
            accountInfoMapper.updateAccountInfo(info);
        }
        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", resultJson.getString("result"));
        return AjaxResult.success(result);
    }

    @Override
    public AjaxResult editGame(AccountInfo accountInfo, Long userId, SalePartner salePartner) {
        int account_id = ReMHWId(accountInfo, salePartner);
        Map<String, Object> params = new HashMap<>();
        params.put("account_id", account_id);
        if ("王者荣耀".equals(accountInfo.getType())) {
            switch (accountInfo.getRegional()) {
                case "安卓Q":
                    params.put("phone_type", 1);
                    break;
                case "安卓WX":
                    params.put("phone_type", 1);
                    break;
                case "苹果Q":
                    params.put("phone_type", 2);
                    break;
                case "苹果WX":
                    params.put("phone_type", 2);
                    break;
            }
        } else if ("和平精英".equals(accountInfo.getType())) {
            switch (accountInfo.getRegional()) {
                case "安卓Q":
                    params.put("phone_type", 1);
                    break;
                case "安卓WX":
                    params.put("phone_type", 1);
                    break;
                case "苹果Q":
                    params.put("phone_type", 2);
                    break;
                case "苹果WX":
                    params.put("phone_type", 2);
                    break;
            }
        } else if ("英雄联盟".equals(accountInfo.getType())) {
//            params.put("phone_type",1);
        } else if ("CF端游".equals(accountInfo.getType())) {
//            params.put("phone_type",1);
        } else if ("原神".equals(accountInfo.getType())) {
//            params.put("phone_type",1);
        }
        params = addOrEditParams(accountInfo, params, 2, salePartner); // 2 表示修改
        params = params(accountInfo, params, salePartner);
        String zhxg = "/Channel/Account/editAccount"; //账号修改接口
        String response = HttpUtils.sendPost(salePartner.getTwoOther() + zhxg,
                StringEscapeUtils.unescapeJava(JSONObject.toJSONString(params).replaceAll("\\s*", "")).replaceAll("\n" +
                        "|\t", ""), "UTF-8");
        JSONObject resultJson = JSONObject.parseObject(response);
        Map<String, Object> result = new HashMap<>();
        if (!"200".equals(resultJson.getString("code"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
        }
        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", resultJson.getString("result"));

        return AjaxResult.success(result);
    }

    @Override
    public AjaxResult delGame(AccountInfo accountInfo, Long userId, SalePartner salePartner) {
        int account_id = ReMHWId(accountInfo, salePartner);
        Map<String, Object> params = new HashMap<>();
        params.put("account_id", account_id);
        params = params(accountInfo, params, salePartner);
        String zhsc = "/Channel/Account/delAccount";// 账号删除接口
        String response = HttpUtils.sendPost(salePartner.getTwoOther() + zhsc,
                StringEscapeUtils.unescapeJava(JSONObject.toJSONString(params).replaceAll("\\s*", "")).replaceAll("\n" +
                        "|\t", ""), "UTF-8");
        JSONObject resultJson = JSONObject.parseObject(response);
        Map<String, Object> result = new HashMap<>();
        if (!"200".equals(resultJson.getString("code"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
            AccountInfo info = accountInfoMapper.selectAccountInfoById(accountInfo.getId());
            info.setMhwid("");
            accountInfoMapper.updateAccountInfo(info);
        }
        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", resultJson.getString("result"));

        return AjaxResult.success(result);
    }

    /**
     * 返回MHWId
     *
     * @param accountInfo
     * @param salePartner
     * @return
     */

    private int ReMHWId(AccountInfo accountInfo, SalePartner salePartner) {
        pdObject(accountInfo, salePartner);
        int MHWid = 1;
        if (StringUtils.isNotEmpty(accountInfo.getMhwid())) {
            try {
                MHWid = Integer.parseInt(accountInfo.getMhwid());
            } catch (Exception e) {
                throw new GlobalException("MHWid转换失败");
            }
        } else {
            throw new GlobalException("未找到MHWid");
        }
        return MHWid;
    }

    /**
     * 判断 accountInfo salePartner 实体是否为空
     *
     * @param accountInfo
     * @param salePartner
     */
    private void pdObject(AccountInfo accountInfo, SalePartner salePartner) {
        if (Objects.isNull(accountInfo)) {
            throw new GlobalException("账号信息对象为空");
        }
        if (Objects.isNull(salePartner)) {
            throw new GlobalException("伙伴对象为空");
        }
    }

    /**
     * 封装 添加和修改账号的的公共参数
     *
     * @param accountInfo
     * @param params
     * @return
     */
    private Map<String, Object> addOrEditParams(AccountInfo accountInfo, Map<String, Object> params, int type,
                                                SalePartner sa) {
        String imgs = "";
        if (Objects.nonNull(accountInfo.getTitleImg())) {
            String titleImgUrl = accountInfo.getTitleImg();
            titleImgUrl = formatImgUrl(titleImgUrl); // 截取 “？” 之前的字符串并返回
            if (!pdhouzhui(titleImgUrl)) {
                throw new GlobalException("标题图片的后缀或无后缀接口不支持");
            }
            imgs = titleImgUrl + "|";
        }
        InfoImg infoImg = new InfoImg();
        infoImg.setInfoId(accountInfo.getId());
        infoImg.setType(Constants.STR_1);
        List<InfoImg> infoImgs = infoImgMapper.selectInfoImgList(infoImg);
        if (!CollectionUtils.isEmpty(infoImgs)) {
//            imgs = imgs + infoImgs.stream().map(i -> i.getImgUrl()).collect(Collectors.joining("|"));
            for (InfoImg img : infoImgs) {
                String imgurl = img.getImgUrl();
                imgurl = formatImgUrl(imgurl);
                if (!pdhouzhui(imgurl)) {
                    throw new GlobalException("附件图片的后缀或无后缀接口不支持");
                }
                imgs = imgs + img.getImgUrl() + "|";
            }
            imgs = imgs.substring(0, imgs.length() - 1);
        } else {
            imgs = imgs + LCConstant.defaultImg;
        }
        params.put("img_url", imgs);

        String title = accountInfo.getDes();
        if (Objects.nonNull(title)) {
            if (title.length() > 100) {
                title = title.substring(0, 90);
            }
            params.put("title", title);  // 商品标题 怎么取值   截取des
        } else {
            params.put("title", "默认标题");
        }
        if (type == 1) {  //add账号需要字段  写死的值 账号修改 不需要再重复请求
            params.put("account_type", 2); // 账号类型，1：初始号，2：成品号
            params.put("role_name", "问客服");   //角色名称  怎么取值  问客服
            params.put("pwd", "111111");//游戏密码  固定111111
            params.put("level", 30);   //游戏等级
            params.put("inscription", 1);//铭文数量
            params.put("bind_phone", 1);//绑定手机，0:未绑定，1：绑定
            params.put("bind_qa", 1);//绑定问题，0:未绑定，1：绑定
            params.put("bind_idcard", 1);//绑定身份证，0:未绑定，1：绑定
            params.put("xy_score", 500);//信誉积分值  500
            params.put("credit_score_lol", 120);//英雄联盟专属-信誉积分值1-120
            params.put("contact_way", "18888888888"); //紧急联系手机号码
            params.put("contact_qq", "111111111");//紧急联系QQ
        }
        String yxzh = descTitle + accountInfo.getId();
        params.put("zh", yxzh); //游戏账号  xyr+id
        BigDecimal bigDecimal = commonApi.addPrice(accountInfo.getPrice(), sa.getSeleep());
        commonApi.setPrice(bigDecimal, accountInfo.getId(), sa);
        params.put("price", new DecimalFormat("0.##").format(bigDecimal)); //商品价格  怎么取值
        String des = accountInfo.getDes();
        String ms = descTitle + accountInfo.getId();
        if (StringUtils.isNotNull(des)) {
            if (des.length() > 490) {
                des = des.substring(0, 490);
            }
        }
        params.put("intro", ms + " " + des); // 商品描述  怎么取值 xyr+id+accountInfo.getDes()
        if (accountInfo.getHeroes() != null) {
            params.put("yx", accountInfo.getHeroes()); //英雄数量
        }
        if (accountInfo.getSkins() != null) {
            params.put("pf", accountInfo.getSkins());//皮肤数量
        }
        String level = accountInfo.getLevel();
        //1.未实名，2：已实名可更改，3：已实名不可更改
        if (Arrays.asList(LCConstant.haveTwoList).contains(level) || Objects.equals("可实名", level) || Objects.equals(
                "邮箱可换绑", level)) {
            params.put("is_auth_account", 2);
        } else if (Objects.equals(LCConstant.nobanggMial, level) || Objects.equals(LCConstant.noMial, level)) {
            params.put("is_auth_account", 1);
        } else {
            params.put("is_auth_account", 3);
        }
        params.put("expiry_day", 60);//有效期天数，30/60/90选其一
        return params;
    }

    /**
     * 封装全局参数 app_id timestamp sign
     *
     * @param accountInfo
     * @param params
     * @param salePartner
     * @return
     */
    private Map<String, Object> params(AccountInfo accountInfo, Map<String, Object> params, SalePartner salePartner) {
        int app_id = Integer.parseInt(salePartner.getSaleKey());
        String appsecret = salePartner.getOther();
        params.put("app_id", app_id);
        int time = (int) (DateUtils.getNowDate().getTime() / 1000);
        params.put("timestamp", time);
        String cover1 = getCover(params);
        cover1 = cover1 + "appsecret=" + appsecret;
        String sign = DigestUtils.md5Hex(cover1);
        params.put("sign", sign);
        return params;
    }

    public String getCover(Map<String, Object> params) {
        StringBuffer resut = new StringBuffer();
        TreeSet<String> sortSet = new TreeSet<>(params.keySet()); //排序
        for (String key : sortSet) {
            if (Objects.nonNull(params.get(key)) && StringUtils.isNotEmpty(String.valueOf(params.get(key)))) {
                String val = params.get(key).toString();
                val = val.replaceAll("\\s*", "");
//                val = StringEscapeUtils.unescapeJava(val);
                val = val.replaceAll("\n|\t", "");
                val = HttpUtil.urlEncode(val, "utf-8");
                val = val.replaceAll("%2A", "*");

                resut.append(key + "=" + val + "&");
            }
        }
        return resut.toString();
    }

    public Map stringTOmap(String b) {
        Map docType = new HashMap();
        java.util.StringTokenizer items;
        for (StringTokenizer entrys = new StringTokenizer(b, ", "); entrys.hasMoreTokens();
             docType.put(items.nextToken(), items.hasMoreTokens() ? ((Object) (items.nextToken())) : null)) {
            items = new StringTokenizer(entrys.nextToken(), "=");
        }
        return docType;
    }

    /**
     * 判断imgUrl里是否包含图片后缀
     *
     * @param str
     * @return
     */
    public boolean pdhouzhui(String str) {
        String image = str.substring(str.lastIndexOf(".") + 1).toLowerCase();
        String houzhui[] = {"jpeg", "jpg", "png", "gif", "webp", "bmp", "ico", ".tif"};
        return Arrays.asList(houzhui).contains(image);
    }

    /**
     * 截取imgUrl  “？” 之前的字符串
     *
     * @param imgUrl
     * @return
     */
    public String formatImgUrl(String imgUrl) {
        if (imgUrl.contains("?")) {
            imgUrl = imgUrl.substring(0, imgUrl.indexOf("?"));
        }
        return imgUrl;
    }

//    public static void getYxlb(){
//        Map<String,Object> params = new HashMap<>();
//        params=params(null,params);
//        String response =HttpUtils.sendPost(url + yxlb, JSONObject.toJSONString(params), "UTF-8");
//        System.out.println("返回的response="+response);
//        JSONObject jsonObject = JSONObject.parseObject(response);
//        String msg = jsonObject.getString("msg");
//        String code = jsonObject.getString("code");
//        JSONArray result=jsonObject.getJSONArray("result");
//        List<Map<String, Object>> resultList = new ArrayList<>();
//        Map zh = new HashMap<>();
//        for (Object o : result) {
//            Map fuwuliebiao = new HashMap<>();
//            String s = JSONObject.toJSONString(o);
//            JSONObject jsonObject1 = JSONObject.parseObject(s);
//            fuwuliebiao.put("id",jsonObject1.getString("id"));
//            fuwuliebiao.put("name",jsonObject1.getString("name"));
//            zh.put(jsonObject1.getString("name"),jsonObject1.getString("id"));
//            resultList.add(fuwuliebiao);
//        }
//    }
//    public static void getYxqf(int gameid){
//        int game_id = gameid;
//        Map<String,Object> params = new HashMap<>();
//        params.put("game_id",game_id);
//        params=params(null,params);
//        String response =HttpUtils.sendPost(url + yxqf, JSONObject.toJSONString(params), "UTF-8");
//        System.out.println("返回的response="+response);
//    }
//
//    private static Map<String, Object> params(AccountInfo accountInfo, Map<String,Object> params) {
//        int app_id = 1003000000;
//        String appsecret = "KAIPXYC6JO13DE9M7NF4LW5R20HBZVTQ";
//        params.put("app_id",app_id);
//        int time = (int) (DateUtils.getNowDate().getTime() / 1000);
//        params.put("timestamp", time);
//        String cover1 = getCovertest(params);
//        cover1 = cover1 + "appsecret=" + appsecret;
//        System.out.println(cover1);
//        String sign = DigestUtils.md5Hex(cover1);
//        params.put("sign", sign);
//        System.out.println("角色列表请求参数="+JSONObject.toJSONString(params));
//        return params;
//    }
//    public static String getCovertest(Map<String,Object> params){
//        StringBuffer resut = new StringBuffer();
//        TreeSet<String> sortSet=new TreeSet<>(params.keySet()); //排序
//        for (String key : sortSet) {
//            if (Objects.nonNull(params.get(key)) && StringUtils.isNotEmpty(String.valueOf(params.get(key)))){
//                String val=params.get(key).toString();
//                val=val.replaceAll("\\s*", "");
//                val=HttpUtil.urlEncode(val,"utf-8");
//                val=val.replaceAll("%2A", "*");
//                resut.append(key+"="+val+"&");
//            }
//        }
//        return resut.toString();
//    }
//

//    static String url="http://maihaowan.zuhaowan.net";
//    static String yxlb="/Channel/Account/getGameList"; //获取游戏列表信息
//    static String yxqf="/Channel/Account/getGameServerList"; //获取游戏区服信息
//    static String zhfb="/Channel/Account/addAccount"; // 账号发布接口
//    static String zhxg="/Channel/Account/editAccount"; //账号修改接口
//    static String zhsc="/Channel/Account/delAccount";// 账号删除接口
//    static String a="{王者荣耀=443, 逆战=24, QQ飞车(手游)=636, 崩坏3=664, 球球大作战=449, Nba2Kol2=761, 梦三国=28, 侠盗猎车手Online=441,
//    穿越火线=11, 糖豆人=1020, 绝地求生=581, 英雄联盟=17, 枪战王者=446, 人类一败涂地=673, 火影忍者（手游）=560, 原神（手游）=1028, 和平精英=683, QQ炫舞手游=679,
//    三国杀手游=699, 使命召唤19：现代战争2=1427, 部落冲突=565, YY号码=23, 蛋仔派对=1117}";

//    public static void main(String[] args) {
////       getYxlb();
////       getYxqf(1028);
////        String imgUrl = "https://images.pxb7.com/images/upload/image/20220723/20220723024502_197757
// .jpg?x-oss-process=style/no-shuiyin";
////        imgUrl=formatImgUrl(imgUrl);
////        System.out.println(imgUrl);
////        String image = imgUrl.substring(imgUrl.lastIndexOf(".") + 1).toLowerCase();
////        System.out.println(image);
////        String houzhui[] = {"jpeg", "jpg", "png", "gif", "webp", "bmp", "ico"};
////        System.out.println(Arrays.asList(houzhui).contains(image));
//    }
}
